package com.dzh.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class JDBCController {
    @Autowired
    JdbcTemplate jdbcTemplate;
//查询数据库里的所以信息
    //没有实体类这么办，数据库里的东西用Map来取
    @GetMapping("/userlist")
    public List<Map<String,Object>> userlist(){
        String sql = "select * from user";
        List<Map<String,Object>> list_map = jdbcTemplate.queryForList(sql);
        return list_map;
    }


    @GetMapping("/addUser")
    public String addUser(){
        String sql ="insert into dichan.user(username,password) values('ooo','99999')";
        jdbcTemplate.update(sql);
        return "update-ok";
    }



}
